<?php

/**
 * @Author: kendy
 * @Date:   2019-12-24 13:52:43
 * @Last Modified by:   jiayanting
 * @Last Modified time: 2020-04-03 11:07:44
 */
namespace app\hotel\controller;

use think\Request;
use app\hotel\model\Hotel as hotelModel;
use think\Session;
use app\common\model\AppraiseModel as am;
vendor('qiniu/php-sdk/autoload.php');
use think\Db;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager; //实例化上传类

class Appraises extends Common
{
	public function appraises()
	{ 
        if (Request::instance()->isAjax()) { 
            $get = Request::instance()->get(); 
            $where = []; 
            $appmodel = new am();
            $hotel_id = Session::get('hotel_id');
            $count = $appmodel->getAppCountByItemId(1,$hotel_id); 
            $pagesize = (int)$get['limit'];
            $page = (int)$get['page'];   
            $data =  $appmodel->getAppList(2, $hotel_id, $page, $pagesize);
            
            return ['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data];

        } else {  
            return view();
        }
	}

  /**
   * [delApp 商家删除评论]
   * @Author   kendy
   * @DateTime 2019-12-25T10:25:50+0800
   * @return   [type]                   [description]
   */
   public function delApp()
   {
        if (Request::instance()->isAjax()) { 
            $post = Request::instance()->post(); 
            $where = [];  
            $app_id = $post['app_id'];
            $appmodel = new am(); 
            $res = $appmodel->delApp($app_id); 
            if(false !== $res)
                return ['code' => 0]; 
            else
            	return ['code'=>1];
        }  
   }

       /**
     * 评论图片
     */
    public function viewImage()
    {
        if (Request::instance()->isAjax()) {
            $post = Request::instance()->post(); 
            $app_id = $post['app_id'];
            $where = ['app_id'=>$app_id]; 
            $datas = Db::name('appraise')->field('images')->where($where)->find();
            $imgArr = explode(',', $datas['images']);
            if(count($imgArr)>0)
            {
            	foreach ($imgArr as $key => $value) {
            		 $res['img_path'][] = $value;
            	}
            } 
            if($res){ 
                return json(['code'=>0,'data'=>$res]);

            }else{
                return ['code'=>1,'message'=>'暂无图片'];
            }
        }
    }

}